<legend>Configuracion >> Tasas</legend>
<form id="form_formula" class="well well-small span9" method="POST" >
    <div class="row">
        <div class="span3">
            <div class="control-group" style="display: inline-block;">
                <label class="control-label" for="inputTipoDoc">F&oacute;rmula</label>
                <div class="controls">
                    <select id="formula" name="formula" class="input-xlarge" onchange="document.getElementById('form_formula').submit();">
                        <option value="0">Seleccione f&oacute;rmula</option>
                        <?php foreach ($this->formulas as $formula) { ?>
                            <option <?php echo $this->formula_id == $formula->getId() ? "selected" : "" ?> value="<?php echo $formula->getId(); ?>">
                                <?php echo $formula->getDescripcion(); ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>
        <div class="span3">
            <?php if ($this->messages) : ?>
                <div class="alert alert-success">
                    <?php echo $this->messages[0]; ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
</form>
<?php if ($this->formula) : ?>
    <form class="well well-small span9" method="POST" action="<?php echo $this->baseUrl("/admin/configuracion/tasanegocio/") ?>">
        <input id="formula_id" name="formula_id" type="hidden" value="<?php echo $this->formula_id ?>" class="input-small" style="text-align:right;" />
        <legend><?php echo $this->titulo ?></legend>
        <?php $i = 1; ?>
        <?php $tasas = $this->formula->obtenerTasasNegocios(); ?>
        <?php foreach ($tasas as $tasa) : ?>
            <?php if ($tasa->getActivo()) : ?>
                <div class="row-fluid">
                    <div class="span1" style="text-align:right;">
                        <h4><?php echo $i ?>)</h4>
                    </div>
                    <div class="span2">
                        <div class="control-group" style="display: inline-block;">
                            <label class="control-label" for="inputTipoDoc">Tasa</label>
                            <div class="controls">
                                <div class="input-append">
                                    <input id="tasa_<?php echo $i ?>" name="tasa_<?php echo $i ?>" type="text" value="<?php echo $tasa->getValor() ?>" class="input-small" style="text-align:right;" />
                                    <span class="add-on">%</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="span3">
                        <div class="control-group" style="display: inline-block;">
                            <label class="control-label" for="inputTipoDoc">Cuotas</label>
                            <div class="controls">
                                <input id="cuota_desde_<?php echo $i ?>" name="cuota_desde_<?php echo $i ?>" type="text" value="<?php echo $tasa->getDesde() ?>" class="input-mini" style="text-align:right;"/> 
                                <b>...</b>
                                <input id="cuota_hasta_<?php echo $i ?>" name="cuota_hasta_<?php echo $i ?>" type="text" value="<?php echo $tasa->getHasta() ?>" class="input-mini" style="text-align:right;"/>
                            </div>
                        </div>
                    </div>
                    <div class="span6">
                        <?php
                        if (empty($this->monto)) {
                            $monto = 100;
                        } else {
                            $monto = $this->monto;
                        }

                        if (empty($this->tasaUpdate)) {
                            $tasaUpdate = $tasa->getValor();
                        } else {
                            $tasaUpdate = $this->tasaUpdate;
                        }
                        ?>
                        <div class="row-fluid">
                            <div class="form-inline">
                                <div class="input-append">
                                    <input id="tasaUpdate" name="tasaUpdate" type="text" value="<?php echo $tasaUpdate; ?>" class="input-small" style="text-align:right;" />
                                    <span class="add-on">%</span>
                                </div>
                                <div class="input-append">
                                    <input   name="monto_act"   id="monto_act" type="text" value="<?php echo $monto; ?>" class="input-mini" style="text-align:right;"/> 
                                    <span class="add-on">$</span>
                                </div>


                                <button type="button" class="btn btn-info" onclick="actualizar();"><i class="icon-repeat"></i> </button>
                            </div> 

                        </div>


                    </div>

                </div>
                <div class="row-fluid">
                     <div class="span1">
                    </div>  
                    <div class="span3">

                        <table class="table table-condensed table-striped">
                            <caption>Actual</caption>
                            <?php
                            for ($index = 1; $index < $tasa->getHasta() + 1; $index++) {
                                $montoPorCuota = ceil($this->formula->obtenerMontoPorCuota($monto, $index, $montoUsuario, $this->usuario->getSucursal()->getId()));
                                ?>
                                <tr> <td style="text-align: center"> <?php echo $index; ?> de  <?php echo $montoPorCuota; ?></td></tr>
                                <?php
                            }
                            ?>
                        </table>
                    </div>
                    <div class="span3">
                    </div>    
                    <div class="span3">
                        <table class="table table-condensed table-striped" >
                            <caption>Actualizado</caption>

                            <?php
                            for ($index = 1; $index < $tasa->getHasta() + 1; $index++) {
                                $montoPorCuota = ceil($this->formula->obtenerMontoPorCuotaConTasaCustom($monto, $index, $montoUsuario, $this->usuario->getSucursal()->getId(), $tasaUpdate));
                                ?>
                                <tr> <td style="text-align: center"> <?php echo $index; ?> de  <?php echo $montoPorCuota; ?> </td></tr>
                                <?php
                            }
                            ?>
                        </table>
                    </div>
                </div>  
                <?php $i += 1; ?>
            <?php endif; ?>
        <?php endforeach; ?>
        <!-- Tasa Vacias -->
        <?php for ($j = $i; $j < 2; $j++) : ?>
            <div class="row-fluid">
                <div class="span1" style="text-align:right;">
                    <h4><?php echo $j ?>)</h4>
                </div>
                <div class="span2">
                    <div class="control-group" style="display: inline-block;">
                        <label class="control-label" for="inputTipoDoc">Tasa</label>
                        <div class="controls">
                            <div class="input-append">
                                <input id="tasa_<?php echo $j ?>" name="tasa_<?php echo $j ?>" type="text" value="" class="input-small" style="text-align:right;" />
                                <span class="add-on">%</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="span3">
                    <div class="control-group" style="display: inline-block;">
                        <label class="control-label" for="inputTipoDoc">Cuotas</label>
                        <div class="controls">
                            <input id="cuota_desde_<?php echo $j ?>" name="cuota_desde_<?php echo $j ?>" type="text" value="" class="input-mini" style="text-align:right;"/> 
                            <b>...</b>
                            <input id="cuota_hasta_<?php echo $j ?>" name="cuota_hasta_<?php echo $j ?>" type="text" value="" class="input-mini" style="text-align:right;"/>
                        </div>
                    </div>
                </div>

            </div>
        <?php endfor; ?>
        <div class="form-actions">
            <button name="form_tasa" type="submit" class="btn btn-primary">Guardar</button>
        </div>
    </form>
    <form id="form_actualizacion" method="post">
        <input type="hidden" name="formula_id" id="formula_id" value="<?php echo $this->formula_id; ?>" >
        <input type="hidden" name="monto" id="monto" value="<?php echo $monto; ?>" >
        <input type="hidden" name="soloActualizaValor" id="soloActualizaValor" value="1" >
        <input type="hidden" name="tasaUpdateRequest" id="tasaUpdateRequest" value="<?php echo $tasaUpdate; ?>" >

    </form>
<?php endif; ?>

<script>
    function actualizar() {

        $('#monto').val($('#monto_act').val());
        $('#tasaUpdateRequest').val($('#tasaUpdate').val());

        $('#form_actualizacion').submit();

    }
</script>
